<?php
// +------------------------------------------------------
// | Name: 星空框架  产品规格价格模型
// +------------------------------------------------------
// | Version: V5.0
// +------------------------------------------------------
// | Author: xkyinzhe <zhonghuaxinxing@sina.cn>
// +------------------------------------------------------
// | Time: 2021-04-27 17:57
// +------------------------------------------------------
declare(strict_types=1);

namespace app\common\model;

use think\model\concern\SoftDelete;

/**
 * @xk 产品规格价格模型
 */
class SpecPrice extends BaseModel
{
  use SoftDelete;
  protected $name = 'specPrice';
  protected $pk = 'spec_price_id';
  protected $deleteTime = 'delete_time';
  /**
   * @xk 写入前操作
   *
   * @method onBeforeWrite
   * @param  [type]                  $data                     [description]
   * @return [type]                                            [description]
   * @Author xkyinzhe                <zhonghuaxinxing@sina.cn>
   * @Time   2021-04-27T10:13:52+080
   */
  public static function onBeforeWrite($data)
  {
      unset($data['act']);
      unset($data['controllers']);
      unset($data['actions']);
      if (!$data->create_time) {
          $data->update_time = $data->create_time = date('Y-m-d H:i:s');
      }
      if($data->sku == ''){
        $sku_key = str_replace('_','',(string)$data->sku_key);
        $data->sku = self::getCodeNo(date('Ymd').$data->goods_id.$sku_key,20,1);
      }
  }
}
